package vsqlbuilder.gui.diagram;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;

public class GConnectionLine {

    private boolean visible;

    private int x1;

    private int y1;

    private int x2;

    private int y2;
    
    private GTable gtableSource;
    
    public GConnectionLine(){
    	hide();
    }

    private static final Stroke SELECTION_STROKE = new BasicStroke(1.0f,
    	    BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] {
    		    3.0f, 3.0f }, 0.0f);
    
    public boolean isVisible() {
    	return this.visible;
    }

    public void show(int x, int y) {

    	this.visible = true;
    	this.x1 = this.x2 = x;
    	this.y1 = this.y2 = y;
    }

    public void show(Point p) {

    	this.visible = true;
    	this.x1 = this.x2 = p.x;
    	this.y1 = this.y2 = p.y;
    }
    
    public void hide() {
    	this.visible = false;
    	this.x1 = this.y1 = this.x2 = this.y2 = 0;
    }

    public void resize(int x, int y) {

	this.x2 = x;
	this.y2 = y;
    }

    public Point getSourcePoint(){
    	Point p = new Point(this.x1,this.y1);
    	return p;
    }
    
    public void paint(Graphics2D g) {

	Color currentColor = g.getColor();
	Stroke currentStroke = g.getStroke();

	g.setColor(Color.WHITE);
	g.drawLine(this.x1, this.y1, this.x2, this.y2);

	g.setColor(Color.BLACK);
	g.setStroke(SELECTION_STROKE);
	g.drawLine(this.x1, this.y1, this.x2, this.y2);

	g.setStroke(currentStroke);
	g.setColor(currentColor);
    }
    
    public void setSource(GTable s){
    	this.gtableSource=s;
    }
    
    public GTable getSource(){
    	return this.gtableSource;
    }
}

